#include <stdio.h>
#include <string.h>
#include <stdlib.h>

char* concat(const char*, const char*);
int readline(char[], int);

int main()
{
    char a[10], b[10];
    printf("Enter two messages: ");
    readline(a, 10);
    readline(b, 10);
    char *c = concat(a, b);

    printf("%s\n", c);
    puts(c);

    return 0;
}

int readline(char str[], int n)
{
    int ch, i = 0;
    while ((ch = getchar()) != '\n') 
        if (i < n)
            str[i++] = ch;
    str[i] = '\0';
    return i;
}

char *concat(const char *s1, const char *s2)
{
    char *result;
    result = malloc(strlen(s1) + strlen(s2) + 1);
    if (result == NULL) {
        printf("malloc failed !");
        exit(EXIT_FAILURE);
    }

    strcpy(result, s1);
    strcat(result, s2);

    return result;
}